﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>编辑打字题</title>
    <link href="../css/main.css" rel="stylesheet" type="text/css" />
    <script src="../js/jquery-1.5.2.min.js" type="text/javascript"></script>
    <link href="../css/jquery.loadmask.css" rel="stylesheet" type="text/css" />
    <script src="../js/ligerui.min.js" type="text/javascript"></script>
     <script src="../Js/json2.js" type="text/javascript"></script>
     <script src="../Js/jquery.loadmask.min.js" type="text/javascript"></script>
     <script src="../Js/conmon.js" type="text/javascript"></script>
    <script type="text/javascript">
        var topicID;
        var anserIndex = 0;
        var pWind;
        $(function () {
            pWind = parent.window.parent.window.getWindow();
            topicID = (pWind != null ? pWind.TopicID : null);
            if (topicID == null)
                topicID = 0;
            var IsView = (pWind != null ? pWind.IsView : false);
            if (IsView)
                $("#btnPost").css("display", "none");

            //获取职务列表
            $.getJSON('../WebServer/TopicMng.ashx?Action=RoleList', { Rnd: Math.random() }, function (data) {
                $.each(data, function (i, item) {
                    var str = "<div style='float:left;width:180px;padding:2px;'>";
                    if (i % 3 == 0 && i != 0)
                        str = "<div style='clear:both;float:left;width:180px;padding:2px;'>";
                    str += "<input type='checkbox' name='chkRole' id='chkRole" + i + "' value='" + item.id + "'/><label for='chkRole" + i + "'>" + item.name + "</label>";
                    str += "</div>";
                    $("#divTopicRole").append(str);
                });
            });
            //topicID=0表示新增,否则修改
            if (topicID != 0) {
                //取题目数据
                var params = { TopicID: topicID, Rnd: Math.random() };
                $.getJSON('../WebServer/TopicMng.ashx?Action=TopicByID', params, function (data) {
                    if (data != null) {
                        $("#txtTitle").val(data.title);
                    }
                });
                //职务列表
                $.getJSON('../WebServer/TopicMng.ashx?Action=TopicRoleListByID', params, function (data) {
                    if (data != null) {
                        $.each(data, function (i, item) {
                            var checkedRole = $("#divTopicRole :checkbox[value='" + item + "']");
                            if (checkedRole != null)
                                checkedRole.attr("checked", true);
                        });
                    }
                });
            }
            $("#btnClose").click(function () { closeRefresh(false, ""); });
        });

        var cuselectnodes = [];
        function SaveData() {
            if ($("#txtTitle").val() == "") {
                showErrorTip("请填写打字内容.");
                return;
            }
            var ctrlRoles = $("#divTopicRole :checkbox[id^='chkRole'][checked=true]");
            if (ctrlRoles.length == 0) {
                showErrorTip("请选择题库.");
                return;
            }
            var topicData = { id: topicID, title: $("#txtTitle").val(), type: 6 };
            var anserList = new Array();
            var roleList = new Array();
            $.each(ctrlRoles, function (i, item) {
                roleList.push($(item).val());
                cuselectnodes.push({ text: $(item).next("label").text(), id: $(item).val() });
            });
            $("#divContent").mask("数据处理中，请稍候......");
            var data = { topic: JSON2.stringify(topicData), anserList: JSON2.stringify(anserList), roleList: JSON2.stringify(roleList), Rnd: Math.random() };
            $.post("../WebServer/TopicMng.ashx?Action=SaveTopic", data, function (msgData) {
                var data = eval("(" + msgData + ")");
                $("#divContent").unmask();
                if (data.IsSuccess == 1) {
                    showAlertOk("保存成功");

                    if (pWind) {
                        pWind.loadGrid();
                        if (cuselectnodes)
                            pWind.reflushTree(cuselectnodes);
                    }
                    closeRefresh(false, "");
                }
                else
                    showWarningTip(data.Msg);
            });
        }
    </script>
    <style type="text/css">
        .table{background-color:#84A0C4;border:1px solid #84A0C4;}
        .td{background-color:#ffffff;}
    </style>
</head>
<body>
    <div id="divContent">
    <table width="100%" cellpadding="1px" cellspacing="1px" class="table">
        <tr style="height:30px">
            <td colspan="2" align="center" class="td" style="font-weight:bold;">编辑打字题</td>
        </tr>
        <tr>
            <td class="td" style="width:10%;" align="right">打字内容：</td>
            <td class="td" style="padding:3px"><textarea id="txtTitle" style="width:99%;font-size:10pt;" rows="12" cols="0" class="l-textarea"></textarea></td>
        </tr>
        <tr>
            <td class="td" style="width:10%;" align="right">职务：</td>
            <td class="td" style="padding:3px">
                <div id="divTopicRole">
                </div>
            </td>
        </tr>
    </table>
    <table width="100%" cellpadding="0" cellspacing="0" style="height:100%;">
        <tr style="height:30px">
            <td  align="center">
                <input type="button" id="btnPost" value="保存" onclick="SaveData();" class="l-button" style="display:inline" />
                <input type="button" id="btnClose" value="关闭"class="l-button" style="display:inline" />
            </td>
        </tr>    
    </table>
    </div>
</body>
</html>
